package com.eleadmin.store.controller;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.store.entity.EntryBillSon;
import com.eleadmin.store.service.EntryBillSonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 入库单子表
 * @author : Doman
 * @date : 2024-02-14 15:00:12
 * @version ：1.0
 */

@Api(tags = "入库单子表")
@RestController
@RequestMapping("/api/store/entryBillSon")
public class EntryBillSonController extends BaseController {

    @Autowired
    private EntryBillSonService entryBillSonService;

    @PreAuthorize("hasAuthority('store:entryBillSon:list')")
    //@ApiOperation("分页查询入库单子表")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, EntryBillSon entryBillSon) throws Exception{
        return entryBillSonService.list(page, entryBillSon, getLoginUser());
    }

    @PreAuthorize("hasAuthority('store:entryBillSon:list')")
    //@ApiOperation("查询全部入库单子表")
    @GetMapping()
    public JsonResult list(EntryBillSon entryBillSon){
        return entryBillSonService.list(entryBillSon, getLoginUser());
    }

    @PreAuthorize("hasAuthority('store:entryBillSon:list')")
    //@ApiOperation("根据id查询入库单子表")
    @GetMapping("calcTotalPrice")
    public JsonResult calcTotalPrice(EntryBillSon entryBillSon) {
        return entryBillSonService.calcTotalPrice(entryBillSon, getLoginUser());
    }

    @PreAuthorize("hasAuthority('store:entryBillSon:list')")
    //@ApiOperation("根据id查询入库单子表")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return entryBillSonService.getById(id);
    }


    @PreAuthorize("hasAuthority('store:entryBillSon:save')")
    @OperationLog
    @ApiOperation(value ="添加入库单子表")
    @PostMapping()
    public JsonResult save(@RequestBody EntryBillSon entryBillSon) {
        try {
            return entryBillSonService.save(entryBillSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('store:entryBillSon:update')")
    @OperationLog
    @ApiOperation(value ="修改入库单子表")
    @PutMapping()
    public JsonResult update(@RequestBody EntryBillSon entryBillSon) throws Exception{
        try {
            return entryBillSonService.update(entryBillSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('store:entryBillSon:remove')")
    @OperationLog
    @ApiOperation(value ="删除入库单子表")
    @PutMapping("remove")
    public JsonResult remove(@RequestBody EntryBillSon entryBillSon) {
        try {
            return entryBillSonService.remove(entryBillSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
